﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Enterprise.Infrastructure;
using Enterprise.Model.Kaifabu;
using Enterprise.Service.Kaifabu;
namespace Enterprise.UI.Web.Modules.Kaifa
{
    public partial class Index : Enterprise.Service.BasePage
    {
        protected int year = (int)Utility.sink("year", Utility.MethodType.Get, 0, 0, Utility.DataType.Int);
        protected string dw = (string)Utility.sink("dw", Utility.MethodType.Get, 0, 0, Utility.DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (year == 0)
            {
                year = DateTime.Now.Year;
            }
            if (string.IsNullOrEmpty(dw))
            {
                dw = "SZK";
            }
            if (!IsPostBack)
            {
                OnStart();
            }
            BindKf();
        }

        private void OnStart()
        {
            OnBindDrop();
        }

        private void OnBindDrop()
        {
            int iNow = DateTime.Now.Year;
            int iPre = iNow - 2;
            int iNext = iNow + 2;
            for (int i = iPre; i <= iNext; i++)
            {
                ddl_ny.Items.Add(new ListItem(i.ToString()));
            }
            ListItem liyear = this.ddl_ny.Items.FindByValue(year.ToString());
            if (liyear != null)
                liyear.Selected = true;
            //绑定单位
            DanweiService dws = new DanweiService();
            ddl_dw.DataSource = dws.GetList("");
            if (this.Language == Service.Translation.Language.ru)
            {
                ddl_dw.DataTextField = "DWMCRU";
            }
            else
            {
                ddl_dw.DataTextField = "DWMC";
            }
            ddl_dw.DataValueField = "DWMC";
            ddl_dw.DataBind();
            ListItem lidw = this.ddl_dw.Items.FindByValue(dw.ToString());
            if (lidw != null)
                lidw.Selected = true;
        }

        protected void ddl_ny_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectIndexChanged();
        }

        protected void ddl_dw_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectIndexChanged();
        }

        private void SelectIndexChanged()
        {
            int _year = (int)Utility.sink(ddl_ny.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Int);
            string _dw = (string)Utility.sink(ddl_dw.UniqueID, Utility.MethodType.Post, 0, 0, Utility.DataType.Str);
            Response.Redirect("Index.aspx?year=" + _year + "&dw=" + _dw + "");
            Response.End();
        }

        private void BindKf()
        {
            string href = "";
            href = "js.aspx?dw=" + dw + "&year=" + year + "&showtable=1&width=870&height=480";
            ClientScript.RegisterStartupScript(this.ClientScript.GetType(), "sc", "<script>$(\"#chart\").empty();$(\"#chart\").append(\"<iframe src=\\\"" + href + "\\\" frameborder=\\\"0\\\" width=\\\"870px\\\" height=\\\"480px\\\" scrolling=\\\"no\\\"></iframe>\");</script>");
        }

    }
}